﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using App.Core.Extensions;

/// <summary>
/// Summary description for ConfigReader
/// </summary>
public static class ConfigReader
{
    private const String ADMIN_EMAIL = "AdminEmail";
    private const String SMTP_HOST = "SmtpHost";
    private const String SMTP_PORT = "SmtpPort";
    private const String SUPPORT_EMAIL = "SupportEmail";
    private const String ERROR_EMAIL = "ErrorEmail";

    private static String GetAppSettingsValue(String key)
    {
        return ConfigurationManager.AppSettings[key];
    }

    public static String AdminEmail
    {
        get
        {
            return GetAppSettingsValue(ADMIN_EMAIL);
        }
    }
    public static String SmtpHost
    {
        get
        {
            return GetAppSettingsValue(SMTP_HOST);
        }
    }
    public static String ErrorEmail
    {
        get
        {
            return GetAppSettingsValue(ERROR_EMAIL);
        }
    }
    public static String JSCalendarDateFormat
    {
        get
        {
            return GetAppSettingsValue("JSCalendarDateFormat");
        }
    }
    public static String CSharpCalendarDateFormat
    {
        get
        {
            return GetAppSettingsValue("CSharpCalendarDateFormat");
        }
    }    
        
    /// <summary>
    /// Get the Configuration Value for SMTP port. If not specified then retuns a default value of 25
    /// </summary>
    public static int SmtpPort
    {
        get
        {
            int port = 0;
            String paramValue = GetAppSettingsValue(SMTP_PORT);
            int.TryParse(paramValue, out port);
            return port == 0 ? 25 : port;
        }
    }
    public static String SupportEmail
    {
        get
        {
            return GetAppSettingsValue(SUPPORT_EMAIL);
        }
    }
    public static bool IsDevelopmentEnvironment
    {
        get
        {
            String value = GetAppSettingsValue("IsDevelopmentEnvironment");
            if (String.Compare(value, "True", true) == 0)
                return true;
            return false;
        }
    }
    public static int SiteBusinessCountryID
    {
        get
        {
            String paramValue = GetAppSettingsValue("SiteBusinessCountryID");
            return paramValue.ToInt();            
        }
    }
    public static string ProviderCompany
    {
        get { return GetAppSettingsValue("ProviderCompany"); }
    }
    public static int DeveloperBusinessTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("DeveloperBusinessTypeID");
            return paramValue.ToInt();            
        }
    }
    public static int IndividualBusinessTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("IndividualBusinessTypeID");
            return paramValue.ToInt();            
        }
    }
    public static int ManagingBodyDesignationID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ManagingBodyDesignationID");
            return paramValue.ToInt();            
        }
    }
    public static int IndividualUserGroupID
    {
        get
        {
            String paramValue = GetAppSettingsValue("IndividualUserGroupID");
            return paramValue.ToInt();            
        }
    }
    public static int DeveloperUserGroupID
    {
        get
        {
            String paramValue = GetAppSettingsValue("DeveloperUserGroupID");
            return paramValue.ToInt();            
        }
    }
    public static int ServiceProviderUserGroupID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ServiceProviderUserGroupID");
            return paramValue.ToInt();            
        }
    }
    public static int ReadyStatusID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ReadyStatusID");
            return paramValue.ToInt();            
        }
    }
    public static int ApartmentPropertyTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ApartmentPropertyTypeID");
            return paramValue.ToInt();            
        }
    }
    public static int LandPropertyTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("LandPropertyTypeID");
            return paramValue.ToInt();
        }
    }
    public static bool ApproveCompaniesByAdmin
    {
        get
        {
            String paramValue = GetAppSettingsValue("ApproveCompaniesByAdmin");
            if (String.Compare(paramValue, "true", true) == 0)
                return true;
            return false;
        }
    }
    public static int ProjectPictureFileTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ProjectPictureFileTypeID");
            return paramValue.ToInt();
        }
    }
    public static int ProjectBrocheureFileTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ProjectBrocheureFileTypeID");
            return paramValue.ToInt();
        }
    }
    public static int ProjectFloorPlanFileTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("ProjectFloorPlanFileTypeID");
            return paramValue.ToInt();
        }
    }
    public static int ProjectListDescriptionWordCount
    {
        get
        {
            String paramValue = GetAppSettingsValue("ProjectListDescriptionWordCount");
            return paramValue.ToInt();
        }
    }
    public static int BuildingMaterialSPID
    {
        get
        {
            String paramValue = GetAppSettingsValue("BuildingMaterialSPID");
            return paramValue.ToInt();
        }
    }
    public static int RealEstateServicesSPID
    {
        get
        {
            String paramValue = GetAppSettingsValue("RealEstateServicesSPID");
            return paramValue.ToInt();
        }
    }
    public static int HomeAppliancesSPID
    {
        get
        {
            String paramValue = GetAppSettingsValue("HomeAppliancesSPID");
            return paramValue.ToInt();
        }
    }
    public static int[] ServiceProviderBusinessTypeIDs
    {
        get
        {
            String paramValue = GetAppSettingsValue("ServiceProviderBusinessTypeIDs");
            if(!paramValue.IsNullOrEmpty())
            {
                String[] parts = paramValue.Split(',');
                List<int> values = new List<int>();
                foreach(String str in parts)
                    values.Add(str.ToInt());
                return values.ToArray();
            }
            int[] ids = { 1, 3, 6, 7 };
            return ids;
        }
    }
    public static int SiteAdminUserGroupID
    {
        get
        {
            String paramValue = GetAppSettingsValue("SiteAdminUserGroupID");
            return paramValue.ToInt();
        }
    }
    public static int OtherPropertyTypeID
    {
        get
        {
            String paramValue = GetAppSettingsValue("OtherPropertyTypeID");
            return paramValue.ToInt();
        }
    }    
}
